/* eslint-disable prefer-const */
{
  //字符串
  function _string() {

    let name: string
    name = "hellosanbao"
    // name = 123  //报错
    console.log(name)
  }


  //数字
  function _number() {

    let age: number
    age = 28   //pass
    // age = 'hello'  //报错，类型错误
    console.log(age)
  }

  //布尔
  function _boolean() {
    let hasMoney: boolean
    hasMoney = false   //pass
    // hasMoney = 'has'  //报错，类型错误
    console.log(hasMoney)
  }

  //数组
  function _array() {
    let arr: string[]   //或者 arr:Array<string>
    arr = ['1', '2'] //pass
    // arr = [1,2] //报错，类型错误
    console.log(arr);

  }

  //null
  function _null() {
    let a: null
    a = null
    // a = '' //报错，类型错误
    console.log(a);

  }

  //undefined
  function _undefined() {
    let a: undefined
    a = undefined
    // a = '' //报错，类型错误
    console.log(a);
  }

  //void
  function _void() {
    let a: void
    // a = null //严格模式报错
    a = undefined
    console.log(a)
  }

  //never
  function _never() {
    let a: never
  }

  //enum
  function _enum() {
    //默认情况下,元素成员的值从0开始，依次累加
    enum Num { frist, second, third }
    console.log(Num) //{0: "frist", 1: "second", 2: "third", frist: 0, second: 1, third: 2}
    console.log(Num[0]) // frist
    console.log(Num.frist) // 0

    //也可以修改成员值
    enum Num2 { frist = 1, second = 3, third = 1 }
    console.log(Num2) //{1: "third", 3: "second", frist: 1, second: 3, third: 1}
    console.log(Num2[1]) // third
    console.log(Num2.third) // 1

    enum Name { one = 'xiaomin', two = 'xiaohong', three = 'xiaogang' }
    console.log(Name) //{one: "xiaomin", two: "xiaohong", three: "xiaogang"}
    console.log(Name.one) //xiaomin
    console.log(Name['xiaomin']) // undefined

    const a: Num = Num.frist
    console.log(a) //0
  }

  // tuple(元组)
  function _tuple() {
    let a: [string, number]
    a = ['xiaomin', 28]
    // a = [1,1] //报错

    //越界访问
    // a[2] = 2 //报错
    // console.log(a[2]) //报错

    console.log(a)
  }

  function _function() {
    type AddFunc = (num1: number, num2: number) => number
    const addfunc: AddFunc = (num1, num2) => {
      return num1 + num2
    }

    function addfunc2(num1: number, num2: number): number {
      return num1 + num2
    }
  }

  //类型断言
  function _assert() {
    function test(val: number | string) {
      // val.slice(0) //报错
      // val.toFixed(1)// 报错
      // (val as string).slice(0)
      (val as number).toFixed(1)
    }
  }



  // _string()
  // _number()
  // _boolean()
  //_array()
  //_null()
  //_undefined()
  //_void()
  //_never()
  // _enum()
  // _tuple()
  // _function()
}